package com.hm.oauth.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.hm.oauth.model.AuthorizeModel;
import com.hm.oauth.repository.AuthorizeRepository;

/**
 * @author shishun.wang
 * @date 下午4:18:44 2016年8月31日
 * @version 1.0
 * @describe 
 */
@Component
public class AuthorizeService {

	private static final Logger logger = LoggerFactory.getLogger(AuthorizeService.class);
	
	@Autowired
	private AuthorizeRepository authorizeRepository;
	
	public void put(String code,String userId){
		AuthorizeModel authorizeModel = new AuthorizeModel();
		{
			authorizeModel.setId(code);
			authorizeModel.setUserId(userId);
		}
		authorizeRepository.save(authorizeModel);
	}
	
	public String get(String code){
		AuthorizeModel authorizeModel = authorizeRepository.findOne(code);
		if(null == authorizeModel){
			logger.debug("authorize");
		}
		
		return authorizeModel.getUserId();
	}
}
